package net.lab1024.sa.gateway.processor;

import net.lab1024.sa.gateway.dto.ApiProcessDTO;
import org.springframework.stereotype.Component;
import reactor.core.publisher.Mono;

//@Component
public class SignProcessor extends AbstractApiProcessor {
    @Override
    protected Mono<Void> doProcess(ApiProcessDTO dto) {
        // 示例：验证请求签名（实际需结合业务密钥逻辑）
        String sign = dto.getHttpRequest().getHeaders().getFirst("X-Sign");
        if (sign == null || !verifySign(sign, dto.getData())) {
            dto.setError(new SecurityException("Invalid signature"));
            return Mono.error(dto.getError());
        }
        return Mono.empty(); // 验证通过，进入下一个处理器
    }

    private boolean verifySign(String sign, Object data) {
        // 实现签名验证逻辑（如MD5/HMAC加密）
        return true;
    }
}